<?php
class IndexController extends Controller {

    public function _init() {
        $this->_assign('config',C());
    }

	public function index() {
		$model = new NewsModel();
		$var1 = $model->getList();
        $this->_assign('list', $var1);
        $this->_display('index_index');
	}
	
	public function test(){
		$token = empty($_GET['token']) ? '' : $_GET['token'];
		if($token === $this->_getToken()) {
			//判定为正常
		} else {
			$this->_redirect(array(
                'c' => 'Index',
                'a' => 'dtest'
				//跳转到某一个控制器的某一个Action
			));
		}
	}

    public function testGet(){
        $b = $_GET['b'];
        if($b)
            echo $b;
    }

    public function stest(){
        echo Path::getBasePath();
        $this->_show("Hello World!");
    }
	
	public function dtest(){
/*
		$test = new PdoDriver();
		$test->prepare('select * from test where id > :id');
		$test->execute(array(
			'id' => '1'
		));
		var_dump($test->getAllByAssocArray());
*/
		
        $test = ScrollPHP::load_model('UserModel'); //new UserModel();
        $rs = $test->test();
        //print_r($rs);
        $this->_assign('var1',$rs);
        $this->_display('dtest');
	}

    public function insert(){

        //$test = new UserModel();
        //$rs = $test->chang(array('uid' => 1,'name' => 'demo'));
        $test2 = new UserModel();
        //$rs2 = $test2->add(array('uid' => 1,'name' => 'demo'));
        $rs4 = $test2->up(array('uid' => 'eq 1'),array('name' => 'demo', 'count' => '+=2'));
        print_r($rs4);
        echo "<hr>";
        $test3 = new UserModel();
        $rs3 = $test3->oneData(1);

        print_r($rs3);

    }

    public function testVerify(){
        Header("Content-type: image/GIF");
        $imagecode=new Imagecode(160,50);
        $imagecode->imageout();
    }

    public function testError(){
        //trigger_error("Test error", E_USER_ERROR);
        trigger_error("Test warning", E_USER_WARNING);
        trigger_error("Test notice", E_USER_NOTICE);
    }

    public function debug(){

        print_r(C("setting=>csspath"));
    }
}